package com.epam.chenjo.ms.feign.integration;



import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.epam.chenjo.ms.feign.EmployeeServiceFeignClient;
import com.epam.chenjo.ms.feign.SalaryServiceFeignClient;
import com.epam.chenjo.ms.model.EmployeeDetails;
import com.epam.chenjo.ms.model.SalaryDetails;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

@Component
public class FeignIntegrationClient {

	private EmployeeServiceFeignClient employeeServiceFeignClient;
	private SalaryServiceFeignClient salaryServiceFeignClient;

	@Autowired
	public FeignIntegrationClient(EmployeeServiceFeignClient employeeServiceFeignClient, SalaryServiceFeignClient salaryServiceFeignClient) {
		this.employeeServiceFeignClient = employeeServiceFeignClient;
		this.salaryServiceFeignClient = salaryServiceFeignClient;
	}
	
//	@Autowired
//	public FeignIntegrationClient(EmployeeServiceFeignClient employeeServiceFeignClient) {
//		this.employeeServiceFeignClient = employeeServiceFeignClient;
//	}

	@HystrixCommand(fallbackMethod = "getEmployeeDetailsFallback")
	public EmployeeDetails getEmployeeDetails(String empId) {
		EmployeeDetails emp = employeeServiceFeignClient.getEmployeeDetails(empId);
		SalaryDetails sal = salaryServiceFeignClient.getSalaries(empId).get(0);
		emp.setSalary(String.valueOf(sal.getAmount()));
		return emp;
	}
	
//	@HystrixCommand(fallbackMethod = "getEmployeeDetailsFallback")
//	public EmployeeDetails getEmployeeDetails(String empId) {
//		EmployeeDetails emp = employeeServiceFeignClient.getEmployeeDetails(empId);
//		
//		return emp;
//	}

	public EmployeeDetails getEmployeeDetailsFallback(String userId) {
		System.out.println("No service available at the moment, please try later.");
		return new EmployeeDetails();
	}

	

}
